<template>
  <div>
    <van-list v-model="loading"
              :finished="finished"
              finished-text="没有更多了"
              :error.sync="error"
              error-text="请求失败，点击重新加载"
              @load="onLoad">
      <van-cell v-for="item in list"
                title-class='van-ellipsis'
                :key="item.reportId"
                :title="item.reportName">
        <template slot="default">
          <van-button type="info"
                      @click="toDetail(item)"
                      size="mini">查看详情</van-button>
        </template>
      </van-cell>
    </van-list>
  </div>
</template>
<script>
import { List, Cell, Button } from 'vant';
import { MyReportList } from '@/api/myReport'
export default {
  name: 'myReport',
  components: {
    [List.name]: List,
    [Cell.name]: Cell,
    [Button.name]: Button
  },
  data () {
    return {
      loading: false,
      finished: false,
      error: false,
      list: [],
      cycle: 'M',
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      }
    }
  },
  methods: {
    onLoad () {
      MyReportList({
        'cycle': this.cycle,
        'pageNum': this.page.currentPage,
        'pageSize': this.page.pageSize
      }).then(res => {
        // eslint-disable-next-line no-console
        console.log(res)
        this.list.push(...res.rows)
        this.loading = false
        if (res.total < this.page.pageSize * this.page.currentPage) {
          this.finished = true
        }
        this.page.currentPage++
      }).catch(() => {
        this.error = true;
      })
    },
    toDetail (item) {
      // eslint-disable-next-line no-console
      console.log(item)
      this.$router.push({
        path: '/reportDetail',
        query: {
          id: item.reportId
        }
      })
    }
  }
}
</script>